package cl.uchile.sketchpad.persistance.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cl.uchile.sketchpad.persistance.model.Slide;

@Repository
public class SlideDaoImpl implements SlideDao {
	
	@PersistenceContext
	private EntityManager em; 

	@Override
	@Transactional(readOnly = true)
	public List<Slide> getAll() {
		TypedQuery<Slide> q = em.createQuery("from Slide", Slide.class);
		return q.getResultList();
	}

	@Override
	@Transactional(readOnly = true)
	public Slide findById(Integer id) {
		return em.find(Slide.class, id);
	}

	@Override
	@Transactional
	public void persist(Slide slide) {
		em.persist(slide);
	}

	@Override
	@Transactional
	public void remove(Slide slide) {
		em.remove(slide);
	}

}
